package cn.harry.cabinet.theme.constants

import cn.harry.cabinet.R
import cn.harry.cabinet.utils.AppConfigKeys

/**
 * 主题系统常量定义
 * 统一管理所有主题相关的常量、配置和资源引用
 */
object ThemeConstants {
    
    /**
     * 主题类型定义
     */
    object ThemeTypes {
        const val CHINA_RED = AppConfigKeys.THEME_CHINA_RED
        const val VIBRANT_ORANGE = AppConfigKeys.THEME_VIBRANT_ORANGE
        const val TECH_BLUE = AppConfigKeys.THEME_TECH_BLUE
    }
    
    /**
     * 配置键名定义
     */
    object ConfigKeys {
        const val TYPE_THEME = AppConfigKeys.TYPE_THEME
        const val KEY_CURRENT_THEME = AppConfigKeys.KEY_CURRENT_THEME
    }
    
    /**
     * 默认值定义
     */
    object Defaults {
        const val DEFAULT_THEME = ThemeTypes.TECH_BLUE
        const val THEME_ANIMATION_DURATION = 300L
        const val STATUS_BAR_ANIMATION_DURATION = 200L
    }
    
    /**
     * 中国红主题色彩常量
     */
    object ChinaRedColors {
        const val PRIMARY = "#DC143C"
        const val PRIMARY_DARK = "#B91C3C"
        const val PRIMARY_LIGHT = "#EF4444"
        const val SECONDARY = "#8B0000"
        const val ACCENT = "#FF6B6B"
        
        // 资源引用
        val primaryColorRes = R.color.china_red_primary
        val primaryDarkColorRes = R.color.china_red_primary_dark
        val primaryLightColorRes = R.color.china_red_primary_light
        val secondaryColorRes = R.color.china_red_secondary
        val accentColorRes = R.color.china_red_accent
        
        // 按钮资源
        val primaryButtonDrawable = R.drawable.button_china_red_primary
        val secondaryButtonDrawable = R.drawable.button_china_red_secondary
        val selectedMenuItemDrawable = R.drawable.nav_menu_item_selected_china_red
    }
    
    /**
     * 活力橙主题色彩常量
     */
    object VibrantOrangeColors {
        const val PRIMARY = "#FF6B35"
        const val PRIMARY_DARK = "#E55A2B"
        const val PRIMARY_LIGHT = "#FF8F66"
        const val SECONDARY = "#FF4500"
        const val ACCENT = "#FFB347"
        
        // 资源引用
        val primaryColorRes = R.color.vibrant_orange_primary
        val primaryDarkColorRes = R.color.vibrant_orange_primary_dark
        val primaryLightColorRes = R.color.vibrant_orange_primary_light
        val secondaryColorRes = R.color.vibrant_orange_secondary
        val accentColorRes = R.color.vibrant_orange_accent
        
        // 按钮资源
        val primaryButtonDrawable = R.drawable.button_vibrant_orange_primary
        val secondaryButtonDrawable = R.drawable.button_vibrant_orange_secondary
        val selectedMenuItemDrawable = R.drawable.nav_menu_item_selected_vibrant_orange
    }
    
    /**
     * 科技蓝主题色彩常量
     */
    object TechBlueColors {
        const val PRIMARY = "#00D4FF"
        const val PRIMARY_DARK = "#0099CC"
        const val PRIMARY_LIGHT = "#66E5FF"
        const val SECONDARY = "#1E3A8A"
        const val ACCENT = "#66E5FF"
        
        // 资源引用
        val primaryColorRes = R.color.tech_blue_primary
        val primaryDarkColorRes = R.color.tech_blue_primary_dark
        val primaryLightColorRes = R.color.tech_blue_primary_light
        val secondaryColorRes = R.color.tech_blue_secondary
        val accentColorRes = R.color.tech_blue_accent
        
        // 按钮资源
        val primaryButtonDrawable = R.drawable.button_tech_blue_primary
        val secondaryButtonDrawable = R.drawable.button_tech_blue_secondary
        val selectedMenuItemDrawable = R.drawable.nav_menu_item_selected_tech_blue
    }
    
    /**
     * 通用颜色常量
     */
    object CommonColors {
        val white = R.color.white
        val black = R.color.black
        val gray = R.color.gray
        val transparent = android.R.color.transparent
        
        // 动态主题颜色
        val themePrimary = R.color.theme_primary
        val themeOnPrimary = R.color.theme_on_primary
        val themeAccent = R.color.theme_accent
        val themeOnSurface = R.color.theme_on_surface
        val themeSurface = R.color.theme_surface
    }
    
    /**
     * 按钮类型常量
     */
    object ButtonTypes {
        const val PRIMARY = "primary"
        const val SECONDARY = "secondary"
        const val ICON_BUTTON = "icon_button"
        const val CARD_BUTTON = "card_button"
    }
    
    /**
     * 按钮ID分类
     */
    object ButtonIds {
        // 主要操作按钮ID列表
        val primaryButtonIds = intArrayOf(
            R.id.btn_save_home_config,
            R.id.startServerButton,
            R.id.saveExternalApiButton,
            R.id.applyConfigButton,
            R.id.confirmButton
        )
        
        // 次要操作按钮ID列表
        val secondaryButtonIds = intArrayOf(
            R.id.searchButton,
            R.id.stopServerButton,
            R.id.checkNetworkButton,
            R.id.cancelButton
        )
        
        // 图标按钮ID列表
        val iconButtonIds = intArrayOf(
            R.id.btn_settings,
            R.id.editButton,
            R.id.deleteButton
        )
    }
    
    /**
     * 按钮文字识别关键词
     */
    object ButtonKeywords {
        // 主要操作关键词
        val primaryKeywords = arrayOf(
            "保存", "确认", "提交", "添加", "启动", "应用",
            "save", "confirm", "submit", "add", "start", "apply"
        )
        
        // 次要操作关键词
        val secondaryKeywords = arrayOf(
            "取消", "重置", "返回", "搜索", "停止", "检查",
            "cancel", "reset", "back", "search", "stop", "check"
        )
    }
    
    /**
     * 导航主题常量
     */
    object Navigation {
        // 导航菜单动画时长
        const val MENU_ANIMATION_DURATION = 250L
        const val HEADER_ANIMATION_DURATION = 200L
        
        // 菜单项样式常量
        const val MENU_ITEM_CORNER_RADIUS = 24f
        const val MENU_ITEM_STROKE_WIDTH = 3
        const val MENU_ITEM_ELEVATION = 4f
        
        // 左侧指示条配置
        const val INDICATOR_WIDTH = 4
        const val INDICATOR_MARGIN = 4
    }
    
    /**
     * 主题样式资源ID映射
     */
    object StyleResources {
        // 按钮样式
        val themeButtonPrimary = R.style.ThemeButtonPrimary
        val themeButtonSecondary = R.style.ThemeButtonSecondary
        val themeImageButton = R.style.ThemeImageButton

        // 主题选择器样式
        val themeSelector = R.style.ThemeSelector
        val themePreviewCard = R.style.ThemePreviewCard
    }
    
    /**
     * 字符串资源常量
     */
    object StringResources {
        // 主题名称
        val themeChinaRed = R.string.theme_china_red
        val themeVibrantOrange = R.string.theme_vibrant_orange
        val themeTechBlue = R.string.theme_tech_blue
        
        // 主题配置
        val themeConfig = R.string.theme_config
        val currentThemeFormat = R.string.current_theme_format
        val themeSwitchedFormat = R.string.theme_switched_format
        val themeRestartNotice = R.string.theme_restart_notice
    }
    
    /**
     * 动画配置常量
     */
    object Animations {
        const val FADE_DURATION = 150L
        const val SLIDE_DURATION = 200L
        const val SCALE_DURATION = 100L
        const val COLOR_TRANSITION_DURATION = 300L
        
        // 缓动函数类型
        const val EASE_IN_OUT = "ease_in_out"
        const val EASE_IN = "ease_in"
        const val EASE_OUT = "ease_out"
        const val LINEAR = "linear"
    }
    
    /**
     * 调试和日志标签
     */
    object LogTags {
        const val THEME_MANAGER = "ThemeManager"
        const val BUTTON_THEME_MANAGER = "ButtonThemeManager"
        const val NAVIGATION_THEME_MANAGER = "NavigationThemeManager"
        const val DYNAMIC_THEME_UPDATER = "DynamicThemeUpdater"
        const val THEME_CONFIG = "ThemeConfig"
    }
    
    /**
     * 获取主题的完整配色方案
     */
    fun getThemeColors(themeType: String) = when (themeType) {
        ThemeTypes.CHINA_RED -> ChinaRedColors
        ThemeTypes.VIBRANT_ORANGE -> VibrantOrangeColors
        ThemeTypes.TECH_BLUE -> TechBlueColors
        else -> TechBlueColors // 默认使用科技蓝
    }
    
    /**
     * 语义化颜色常量
     */
    object SemanticColors {
        // Success 成功色
        const val SUCCESS = "#10B981"
        const val SUCCESS_DARK = "#059669"
        const val SUCCESS_LIGHT = "#34D399"
        const val SUCCESS_BACKGROUND = "#ECFDF5"
        const val SUCCESS_BACKGROUND_DARK = "#064E3B"
        const val SUCCESS_TEXT = "#065F46"
        const val SUCCESS_TEXT_DARK = "#D1FAE5"
        
        // Warning 警告色
        const val WARNING = "#F59E0B"
        const val WARNING_DARK = "#D97706"
        const val WARNING_LIGHT = "#FBBF24"
        const val WARNING_BACKGROUND = "#FFFBEB"
        const val WARNING_BACKGROUND_DARK = "#78350F"
        const val WARNING_TEXT = "#92400E"
        const val WARNING_TEXT_DARK = "#FEF3C7"
        
        // Danger 危险色
        const val DANGER = "#EF4444"
        const val DANGER_DARK = "#DC2626"
        const val DANGER_LIGHT = "#F87171"
        const val DANGER_BACKGROUND = "#FEF2F2"
        const val DANGER_BACKGROUND_DARK = "#7F1D1D"
        const val DANGER_TEXT = "#991B1B"
        const val DANGER_TEXT_DARK = "#FEE2E2"
        
        // Info 信息色
        const val INFO = "#3B82F6"
        const val INFO_DARK = "#2563EB"
        const val INFO_LIGHT = "#60A5FA"
        const val INFO_BACKGROUND = "#EFF6FF"
        const val INFO_BACKGROUND_DARK = "#1E3A8A"
        const val INFO_TEXT = "#1E40AF"
        const val INFO_TEXT_DARK = "#DBEAFE"
        
        // 资源引用
        val successColorRes = R.color.semantic_success
        val successDarkColorRes = R.color.semantic_success_dark
        val successLightColorRes = R.color.semantic_success_light
        val successBackgroundColorRes = R.color.semantic_success_background
        val successTextColorRes = R.color.semantic_success_text
        
        val warningColorRes = R.color.semantic_warning
        val warningDarkColorRes = R.color.semantic_warning_dark
        val warningLightColorRes = R.color.semantic_warning_light
        val warningBackgroundColorRes = R.color.semantic_warning_background
        val warningTextColorRes = R.color.semantic_warning_text
        
        val dangerColorRes = R.color.semantic_danger
        val dangerDarkColorRes = R.color.semantic_danger_dark
        val dangerLightColorRes = R.color.semantic_danger_light
        val dangerBackgroundColorRes = R.color.semantic_danger_background
        val dangerTextColorRes = R.color.semantic_danger_text
        
        val infoColorRes = R.color.semantic_info
        val infoDarkColorRes = R.color.semantic_info_dark
        val infoLightColorRes = R.color.semantic_info_light
        val infoBackgroundColorRes = R.color.semantic_info_background
        val infoTextColorRes = R.color.semantic_info_text
    }
    
    /**
     * 中性色常量
     */
    object NeutralColors {
        const val NEUTRAL_50 = "#F9FAFB"
        const val NEUTRAL_100 = "#F3F4F6"
        const val NEUTRAL_200 = "#E5E7EB"
        const val NEUTRAL_300 = "#D1D5DB"
        const val NEUTRAL_400 = "#9CA3AF"
        const val NEUTRAL_500 = "#6B7280"
        const val NEUTRAL_600 = "#4B5563"
        const val NEUTRAL_700 = "#374151"
        const val NEUTRAL_800 = "#1F2937"
        const val NEUTRAL_900 = "#111827"
        
        // 文本颜色常量
        const val TEXT_PRIMARY = "#111827"
        const val TEXT_SECONDARY = "#6B7280"
        const val TEXT_TERTIARY = "#9CA3AF"
        const val TEXT_DISABLED = "#D1D5DB"
        
        const val TEXT_PRIMARY_DARK = "#F9FAFB"
        const val TEXT_SECONDARY_DARK = "#D1D5DB"
        const val TEXT_TERTIARY_DARK = "#9CA3AF"
        const val TEXT_DISABLED_DARK = "#4B5563"
        
        // 背景颜色常量
        const val BACKGROUND = "#FFFFFF"
        const val BACKGROUND_SECONDARY = "#F9FAFB"
        const val BACKGROUND_TERTIARY = "#F3F4F6"
        
        const val BACKGROUND_DARK = "#111827"
        const val BACKGROUND_SECONDARY_DARK = "#1F2937"
        const val BACKGROUND_TERTIARY_DARK = "#374151"
        
        // 边框颜色常量
        const val BORDER = "#E5E7EB"
        const val BORDER_SECONDARY = "#D1D5DB"
        const val BORDER_DARK = "#374151"
        const val BORDER_SECONDARY_DARK = "#4B5563"
        
        // 资源引用
        val neutral50ColorRes = R.color.neutral_50
        val neutral100ColorRes = R.color.neutral_100
        val neutral200ColorRes = R.color.neutral_200
        val neutral300ColorRes = R.color.neutral_300
        val neutral400ColorRes = R.color.neutral_400
        val neutral500ColorRes = R.color.neutral_500
        val neutral600ColorRes = R.color.neutral_600
        val neutral700ColorRes = R.color.neutral_700
        val neutral800ColorRes = R.color.neutral_800
        val neutral900ColorRes = R.color.neutral_900
        
        val textPrimaryColorRes = R.color.neutral_text_primary
        val textSecondaryColorRes = R.color.neutral_text_secondary
        val textTertiaryColorRes = R.color.neutral_text_tertiary
        val textDisabledColorRes = R.color.neutral_text_disabled
        
        val backgroundColorRes = R.color.neutral_background
        val backgroundSecondaryColorRes = R.color.neutral_background_secondary
        val backgroundTertiaryColorRes = R.color.neutral_background_tertiary
        
        val borderColorRes = R.color.neutral_border
        val borderSecondaryColorRes = R.color.neutral_border_secondary
    }
    
    /**
     * 主题适配语义化颜色常量
     */
    object ThemeSemanticColors {
        // Success
        val themeSuccessColorRes = R.color.theme_success
        val themeSuccessDarkColorRes = R.color.theme_success_dark
        val themeSuccessLightColorRes = R.color.theme_success_light
        val themeSuccessBackgroundColorRes = R.color.theme_success_background
        val themeSuccessTextColorRes = R.color.theme_success_text
        
        // Warning
        val themeWarningColorRes = R.color.theme_warning
        val themeWarningDarkColorRes = R.color.theme_warning_dark
        val themeWarningLightColorRes = R.color.theme_warning_light
        val themeWarningBackgroundColorRes = R.color.theme_warning_background
        val themeWarningTextColorRes = R.color.theme_warning_text
        
        // Danger
        val themeDangerColorRes = R.color.theme_danger
        val themeDangerDarkColorRes = R.color.theme_danger_dark
        val themeDangerLightColorRes = R.color.theme_danger_light
        val themeDangerBackgroundColorRes = R.color.theme_danger_background
        val themeDangerTextColorRes = R.color.theme_danger_text
        
        // Info
        val themeInfoColorRes = R.color.theme_info
        val themeInfoDarkColorRes = R.color.theme_info_dark
        val themeInfoLightColorRes = R.color.theme_info_light
        val themeInfoBackgroundColorRes = R.color.theme_info_background
        val themeInfoTextColorRes = R.color.theme_info_text
        
        // Neutral
        val themeNeutralColorRes = R.color.theme_neutral
        val themeNeutralDarkColorRes = R.color.theme_neutral_dark
        val themeNeutralLightColorRes = R.color.theme_neutral_light
        val themeNeutralBackgroundColorRes = R.color.theme_neutral_background
        val themeNeutralTextColorRes = R.color.theme_neutral_text
    }
    
    /**
     * 语义化颜色类型枚举
     */
    enum class SemanticColorType(val key: String, val displayName: String) {
        SUCCESS("success", "成功"),
        WARNING("warning", "警告"),
        DANGER("danger", "危险"),
        INFO("info", "信息"),
        NEUTRAL("neutral", "中性"),
        PRIMARY("primary", "主色")
    }
    
    /**
     * 颜色变体枚举
     */
    enum class ColorVariant(val key: String, val displayName: String) {
        DEFAULT("default", "默认"),
        DARK("dark", "深色"),
        LIGHT("light", "浅色"),
        BACKGROUND("background", "背景"),
        TEXT("text", "文本"),
        BORDER("border", "边框")
    }
    
    /**
     * 根据语义化颜色类型和变体获取颜色资源
     */
    fun getSemanticColorResource(type: SemanticColorType, variant: ColorVariant = ColorVariant.DEFAULT): Int {
        return when (type) {
            SemanticColorType.SUCCESS -> when (variant) {
                ColorVariant.DEFAULT -> SemanticColors.successColorRes
                ColorVariant.DARK -> SemanticColors.successDarkColorRes
                ColorVariant.LIGHT -> SemanticColors.successLightColorRes
                ColorVariant.BACKGROUND -> SemanticColors.successBackgroundColorRes
                ColorVariant.TEXT -> SemanticColors.successTextColorRes
                ColorVariant.BORDER -> R.color.semantic_success_border
            }
            SemanticColorType.WARNING -> when (variant) {
                ColorVariant.DEFAULT -> SemanticColors.warningColorRes
                ColorVariant.DARK -> SemanticColors.warningDarkColorRes
                ColorVariant.LIGHT -> SemanticColors.warningLightColorRes
                ColorVariant.BACKGROUND -> SemanticColors.warningBackgroundColorRes
                ColorVariant.TEXT -> SemanticColors.warningTextColorRes
                ColorVariant.BORDER -> R.color.semantic_warning_border
            }
            SemanticColorType.DANGER -> when (variant) {
                ColorVariant.DEFAULT -> SemanticColors.dangerColorRes
                ColorVariant.DARK -> SemanticColors.dangerDarkColorRes
                ColorVariant.LIGHT -> SemanticColors.dangerLightColorRes
                ColorVariant.BACKGROUND -> SemanticColors.dangerBackgroundColorRes
                ColorVariant.TEXT -> SemanticColors.dangerTextColorRes
                ColorVariant.BORDER -> R.color.semantic_danger_border
            }
            SemanticColorType.INFO -> when (variant) {
                ColorVariant.DEFAULT -> SemanticColors.infoColorRes
                ColorVariant.DARK -> SemanticColors.infoDarkColorRes
                ColorVariant.LIGHT -> SemanticColors.infoLightColorRes
                ColorVariant.BACKGROUND -> SemanticColors.infoBackgroundColorRes
                ColorVariant.TEXT -> SemanticColors.infoTextColorRes
                ColorVariant.BORDER -> R.color.semantic_info_border
            }
            SemanticColorType.NEUTRAL -> when (variant) {
                ColorVariant.DEFAULT -> NeutralColors.neutral500ColorRes
                ColorVariant.DARK -> NeutralColors.neutral700ColorRes
                ColorVariant.LIGHT -> NeutralColors.neutral300ColorRes
                ColorVariant.BACKGROUND -> NeutralColors.backgroundColorRes
                ColorVariant.TEXT -> NeutralColors.textPrimaryColorRes
                ColorVariant.BORDER -> NeutralColors.borderColorRes
            }
            SemanticColorType.PRIMARY -> when (variant) {
                ColorVariant.DEFAULT -> R.color.theme_primary
                ColorVariant.DARK -> R.color.theme_primary_dark
                ColorVariant.LIGHT -> R.color.theme_primary_light
                ColorVariant.BACKGROUND -> R.color.theme_background
                ColorVariant.TEXT -> R.color.theme_on_primary
                ColorVariant.BORDER -> R.color.theme_divider
            }
        }
    }
    
    /**
     * 根据语义化颜色类型和变体获取主题适配颜色资源
     */
    fun getThemeSemanticColorResource(type: SemanticColorType, variant: ColorVariant = ColorVariant.DEFAULT): Int {
        return when (type) {
            SemanticColorType.SUCCESS -> when (variant) {
                ColorVariant.DEFAULT -> ThemeSemanticColors.themeSuccessColorRes
                ColorVariant.DARK -> ThemeSemanticColors.themeSuccessDarkColorRes
                ColorVariant.LIGHT -> ThemeSemanticColors.themeSuccessLightColorRes
                ColorVariant.BACKGROUND -> ThemeSemanticColors.themeSuccessBackgroundColorRes
                ColorVariant.TEXT -> ThemeSemanticColors.themeSuccessTextColorRes
                else -> ThemeSemanticColors.themeSuccessColorRes
            }
            SemanticColorType.WARNING -> when (variant) {
                ColorVariant.DEFAULT -> ThemeSemanticColors.themeWarningColorRes
                ColorVariant.DARK -> ThemeSemanticColors.themeWarningDarkColorRes
                ColorVariant.LIGHT -> ThemeSemanticColors.themeWarningLightColorRes
                ColorVariant.BACKGROUND -> ThemeSemanticColors.themeWarningBackgroundColorRes
                ColorVariant.TEXT -> ThemeSemanticColors.themeWarningTextColorRes
                else -> ThemeSemanticColors.themeWarningColorRes
            }
            SemanticColorType.DANGER -> when (variant) {
                ColorVariant.DEFAULT -> ThemeSemanticColors.themeDangerColorRes
                ColorVariant.DARK -> ThemeSemanticColors.themeDangerDarkColorRes
                ColorVariant.LIGHT -> ThemeSemanticColors.themeDangerLightColorRes
                ColorVariant.BACKGROUND -> ThemeSemanticColors.themeDangerBackgroundColorRes
                ColorVariant.TEXT -> ThemeSemanticColors.themeDangerTextColorRes
                else -> ThemeSemanticColors.themeDangerColorRes
            }
            SemanticColorType.INFO -> when (variant) {
                ColorVariant.DEFAULT -> ThemeSemanticColors.themeInfoColorRes
                ColorVariant.DARK -> ThemeSemanticColors.themeInfoDarkColorRes
                ColorVariant.LIGHT -> ThemeSemanticColors.themeInfoLightColorRes
                ColorVariant.BACKGROUND -> ThemeSemanticColors.themeInfoBackgroundColorRes
                ColorVariant.TEXT -> ThemeSemanticColors.themeInfoTextColorRes
                else -> ThemeSemanticColors.themeInfoColorRes
            }
            SemanticColorType.NEUTRAL -> when (variant) {
                ColorVariant.DEFAULT -> ThemeSemanticColors.themeNeutralColorRes
                ColorVariant.DARK -> ThemeSemanticColors.themeNeutralDarkColorRes
                ColorVariant.LIGHT -> ThemeSemanticColors.themeNeutralLightColorRes
                ColorVariant.BACKGROUND -> ThemeSemanticColors.themeNeutralBackgroundColorRes
                ColorVariant.TEXT -> ThemeSemanticColors.themeNeutralTextColorRes
                else -> ThemeSemanticColors.themeNeutralColorRes
            }
            SemanticColorType.PRIMARY -> when (variant) {
                ColorVariant.DEFAULT -> R.color.theme_primary
                ColorVariant.DARK -> R.color.theme_primary_dark
                ColorVariant.LIGHT -> R.color.theme_primary_light
                ColorVariant.BACKGROUND -> R.color.theme_background
                ColorVariant.TEXT -> R.color.theme_on_primary
                else -> R.color.theme_primary
            }
        }
    }

    /**
     * 验证主题类型是否有效
     */
    fun isValidThemeType(themeType: String): Boolean {
        return themeType in arrayOf(
            ThemeTypes.CHINA_RED,
            ThemeTypes.VIBRANT_ORANGE,
            ThemeTypes.TECH_BLUE
        )
    }
}